//
//  ProductLibTableviewCell.m
//  LazyCat
//
//  Created by jike on 16/4/29.
//  Copyright (c) 2016年 zhanshu. All rights reserved.
//

#import "ProductLibTableviewCell.h"

@implementation ProductLibTableviewCell

- (void)awakeFromNib {
    // Initialization code
}
-(void)setRowOfCell:(NSInteger)rowOfCell {
    _rowOfCell = rowOfCell;
}
- (void)drawRect:(CGRect)rect {
    self.addBtn.layer.cornerRadius = 15;
    self.addBtn.layer.masksToBounds = YES;
    self.addBtn.layer.borderWidth = 1;
    self.addBtn.layer.borderColor = SetColor(221, 221, 221, 1).CGColor;
}
//- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
//    [super setSelected:selected animated:animated];
//    
//}
- (void) setEditing:(BOOL)editting animated:(BOOL)animated
{
    if (self.editing == editting)
    {
        return;
    }
    
    [super setEditing:editting animated:animated];
    
    if (editting)
    {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundView = [[UIView alloc] init];
        self.backgroundView.backgroundColor = [UIColor whiteColor];
        
        if (_m_checkImageView == nil)
        {
            _m_checkImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 23.3, 23.3)];
            _m_checkImageView.backgroundColor = [UIColor whiteColor];
            [self addSubview:_m_checkImageView];
        }
        [self bringSubviewToFront:_m_checkImageView];
        [self setChecked:_m_checked];
        _m_checkImageView.center = CGPointMake(-CGRectGetWidth(_m_checkImageView.frame) * 0.5,CGRectGetHeight(self.bounds) * 0.5);
        _m_checkImageView.alpha = 0.0;
        [self setCheckImageViewCenter:CGPointMake(23, CGRectGetHeight(self.bounds) * 0.5 + 1)alpha:1.0 animated:animated];
    }
    else
    {
        _m_checked = NO;
        self.selectionStyle = UITableViewCellSelectionStyleDefault;
        self.backgroundView = nil;
        
        if (_m_checkImageView)
        {
            [self setCheckImageViewCenter:CGPointMake(-CGRectGetWidth(_m_checkImageView.frame) * 0.5,CGRectGetHeight(self.bounds) * 0.5)alpha:0.0 animated:animated];
        }
    }
}
- (void) setCheckImageViewCenter:(CGPoint)pt alpha:(CGFloat)alpha animated:(BOOL)animated
{
    if (animated)
    {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationBeginsFromCurrentState:YES];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.3];
        
        _m_checkImageView.center = pt;
        _m_checkImageView.alpha = alpha;
        
        [UIView commitAnimations];
    }
    else
    {
        _m_checkImageView.center = pt;
        _m_checkImageView.alpha = alpha;
    }
}
- (void) setChecked:(BOOL)checked
{
    if (checked)
    {
        _m_checkImageView.image = [UIImage imageNamed:@"btn_delete"];
//Unselected.png
//        self.backgroundView.backgroundColor = [UIColor colorWithRed:223.0/255.0 green:230.0/255.0 blue:250.0/255.0 alpha:1.0];
        self.backgroundView.backgroundColor = [UIColor whiteColor];
    }
    else
    {//Selected.png
        _m_checkImageView.image = [UIImage imageNamed:@"btn_choicee"];
        self.backgroundView.backgroundColor = [UIColor whiteColor];
    }
    _m_checked = checked;
}

@end
